package com.java.utils;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Map;

public class HttpParamUtil {

    private static final Logger log = LogManager.getLogger(HttpParamUtil.class);

    /**
     * 获取requestBody参数
     */
    public static JSONObject paramToJson(String param) {
        Map<String, Object> paramMap = paramToMap(param);
        JSONObject json = new JSONObject();
        json.putAll(paramMap);
        return json;
    }

    public static Map<String, Object> paramToMap(String param) {
        try {
            Map map = JSONObject.parseObject(param.toString(), Map.class);
            return map;
        } catch (Exception e) {
            log.error("输入参数不正确", e);
            return Maps.newHashMap();
        }

    }

}

